Pie charts
The PieChart control draws pie and doughnut charts with PieSeries. Each series is a slice: the slices share the
circle in proportion to their values. This article covers the control and the pie series together. The same control
also draws gauges, see the gauges article.
This article highlights the most used features. Every property is listed in the API explorer: PieChart and PieSeries.
Basic pie
Add one PieSeries with one value for every slice. The angle of a slice is its value divided by the sum of the
values of all the series. By default the first slice starts at 3 o'clock and the next ones follow clockwise.

@page "/Pies/Basic"
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore.SkiaSharpView.Drawing.Geometries
@using LiveChartsCore.SkiaSharpView.VisualElements
@using LiveChartsCore.SkiaSharpView.Painting
@using SkiaSharp
<PieChart
@ref="Chart"
Series="Series"
Title="Title">
</PieChart>
@code {
private ISeries[] Series { get; set; }
private DrawnLabelVisual Title { get; set; }
protected override void OnInitialized()
{
Series = new ISeries[]
{
new PieSeries<double> { Name = "Mary", Values = new double[] { 10 } },
new PieSeries<double> { Name = "John", Values = new double[] { 20 } },
new PieSeries<double> { Name = "Alice", Values = new double[] { 30 } },
new PieSeries<double> { Name = "Bob", Values = new double[] { 40 } },
new PieSeries<double> { Name = "Charlie", Values = new double[] { 50 } }
};
Title = new DrawnLabelVisual(
new LabelGeometry
{
Text = "My chart title",
TextSize = 25,
Padding = new LiveChartsCore.Drawing.Padding(15),
});
}
public PieChart Chart;
}
In C#, create one series per slice:
Series = new ISeries[]
{
new PieSeries<double> { Values = new double[] { 2 } },
new PieSeries<double> { Values = new double[] { 4 } },
new PieSeries<double> { Values = new double[] { 1 } },
new PieSeries<double> { Values = new double[] { 4 } },
new PieSeries<double> { Values = new double[] { 3 } }
};
The AsPieSeries extension, in the LiveChartsCore.SkiaSharpView.Extensions namespace, builds the same collection
from any IEnumerable<T>: every item becomes a series with that item as its only value. Its optional argument takes
the item and its series, to set the properties of each series:
Series = new[] { 2, 4, 1, 4, 3 }.AsPieSeries((value, series) =>
{
series.Name = $"Slice {value}";
});
A series with more than one value draws one ring per value, see nested pies.
Doughnut
MaxRadialColumnWidth caps the width of the slices, from the inner to the outer edge, in pixels. When the slices
would be wider, they keep their outer edge and the center of the pie is left empty, which draws a doughnut that
keeps the same ring width at any chart size. It is double.MaxValue by default.

@page "/Pies/Doughnut"
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Blazor
<PieChart
Series="Series">
</PieChart>
@code {
private ISeries[] Series { get; set; }
protected override void OnInitialized()
{
Series = new ISeries[]
{
new PieSeries<double> { Name = "Mary", Values = new double[] { 10 }, MaxRadialColumnWidth = 60 },
new PieSeries<double> { Name = "John", Values = new double[] { 20 }, MaxRadialColumnWidth = 60 },
new PieSeries<double> { Name = "Alice", Values = new double[] { 30 }, MaxRadialColumnWidth = 60 },
new PieSeries<double> { Name = "Bob", Values = new double[] { 40 }, MaxRadialColumnWidth = 60 },
new PieSeries<double> { Name = "Charlie", Values = new double[] { 50 }, MaxRadialColumnWidth = 60 }
};
}
}

RadialAlign sets which edge the slice keeps when it is capped: Outer (the default), Center or Inner.
InnerRadius sets the radius of the hole instead, in pixels. The hole keeps its size and the ring gets thinner when
the chart gets smaller:
var pieSeries = new PieSeries<int>
{
Values = new[] { 4 },
InnerRadius = 50 // mark
};

CornerRadius rounds the corners of every slice, in pixels, and InvertedCornerRadius inverts the direction of the
curve.
Pushout
Pushout is the distance in pixels between the center of the chart and the slice. HoverPushout is the push-out
while the pointer is over the slice, 20 by default; set it to 0 to keep the slices in place on hover. The chart
leaves room for the largest Pushout or HoverPushout of its series, so a slice that moves out stays inside the
control.

@page "/Pies/Pushout"
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Blazor
<PieChart
Series="Series">
</PieChart>
@code {
private ISeries[] Series { get; set; }
protected override void OnInitialized()
{
Series = new ISeries[]
{
// pushes out Maria's slice 30 pixels.
new PieSeries<double> { Name = "Maria", Values = new double[] { 8 }, Pushout = 30 },
new PieSeries<double> { Name = "Susan", Values = new double[] { 6 } },
new PieSeries<double> { Name = "Charles", Values = new double[] { 5 } },
new PieSeries<double> { Name = "Fiona", Values = new double[] { 3 } },
new PieSeries<double> { Name = "George", Values = new double[] { 3 } }
};
}
}

var pieSeries = new PieSeries<int>
{
Values = new[] { 4 },
Pushout = 40 // mark
};
Rotation and direction
The PieChart has three properties that set where and how the slices are drawn:
InitialRotationis the angle, in degrees, where the first slice starts,0by default, which is 3 o'clock. Angles grow clockwise, so-90starts the pie at 12 o'clock.MaxAngleis the angle the whole pie covers, in degrees,360by default.270draws three quarters of a circle.IsClockwiseistrueby default. When it isfalsethe slices follow counterclockwise, and the first slice starts atInitialRotationplusMaxAngle(the same point whenMaxAngleis360).

<PieChart
Series="series"
InitialRotation="-90"
MaxAngle="270"
IsClockwise="false">
</PieChart>
A change in InitialRotation or MaxAngle is animated, as any other change in the chart:


Max value
By default the slices fill the whole MaxAngle, because the total of the pie is the sum of the values. The
MaxValue property of the chart sets that total instead: with MaxValue = 100, a slice with a value of 25 takes a
quarter of the MaxAngle, and when the values add up to less than 100 part of the circle stays empty. Values above
MaxValue are cut at MaxValue. It is double.NaN by default, which means the sum of the values.
<PieChart
Series="series"
MaxValue="100">
</PieChart>
MinValue and the series property IsRelativeToMinValue are meant for gauges, see the
gauges article.
Stroke and fill paints
When Fill is not set, LiveCharts picks it from the current theme, based on the position of the series in the
chart's series collection. The default theme draws pie series with no Stroke.
Stroke draws the border of the slice:

Series = new ISeries[]
{
new PieSeries<double>
{
Values = new double[] { 4 },
Pushout = 8,
Stroke = new SolidColorPaint(SKColors.Red) { StrokeThickness = 3 } // mark
},
new PieSeries<double> { Values = new double[] { 2 } },
new PieSeries<double> { Values = new double[] { 1 } },
new PieSeries<double> { Values = new double[] { 4 } },
new PieSeries<double> { Values = new double[] { 3 } }
};
Fill paints the inside of the slice:

Series = new ISeries[]
{
new PieSeries<double>
{
Values = new double[] { 4 },
Pushout = 8,
Fill = new SolidColorPaint(SKColors.Yellow) // mark
},
new PieSeries<double> { Values = new double[] { 2 } },
new PieSeries<double> { Values = new double[] { 1 } },
new PieSeries<double> { Values = new double[] { 4 } },
new PieSeries<double> { Values = new double[] { 3 } }
};
Paints can also draw gradients and dashed lines, see the Paints article.
Data labels
Set ShowDataLabels to true to draw a label on every slice; setting DataLabelsPaint also shows them. When
DataLabelsPaint is not set, the theme picks it: a color that reads on the slice, or the text color of the theme for
outer labels. DataLabelsSize sets the text size, 16 by default, and DataLabelsFormatter takes the point and
returns the text, the value by default.
DataLabelsPosition places the label:
Middle, the default, inside the slice, at the middle of its angle.Outer, outside the slice, see outer labels.StartandEnd, at the edge where the slice starts or ends, rotated along that edge.ChartCenter, at the center of the chart, used by gauges.
Series = new ISeries[]
{
new PieSeries<double>
{
Values = new double[] { 8 },
DataLabelsPaint = new SolidColorPaint(SKColors.Black),
DataLabelsSize = 22,
// all the positions:
// https://livecharts.dev/api/2.2.0/LiveChartsCore.Measure.PolarLabelsPosition
DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Middle,
DataLabelsFormatter = point => point.Coordinate.PrimaryValue.ToString("N2") + " elements"
},
new PieSeries<double>
{
Values = new double[] { 6 },
DataLabelsPaint = new SolidColorPaint(SKColors.Black),
DataLabelsSize = 22,
DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Middle,
DataLabelsFormatter = point => point.Coordinate.PrimaryValue.ToString("N2") + " elements"
},
new PieSeries<double>
{
Values = new double[] { 4 },
DataLabelsPaint = new SolidColorPaint(SKColors.Black),
DataLabelsSize = 22,
DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Middle,
DataLabelsFormatter = point => point.Coordinate.PrimaryValue.ToString("N2") + " elements"
}
};

Every point of a pie series has a StackedValue property: its Total is the sum of the slices and its Share is
the part of the point in that total, from 0 to 1. This sample uses them in the labels and the tooltips, and
gives every series a different OuterRadiusOffset (see nightingale rose):

@page "/Pies/Custom"
@using LiveChartsCore
@using LiveChartsCore.Kernel
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Blazor
<PieChart
Series="Series"
InitialRotation="-90">
</PieChart>
@code {
private ISeries[] Series { get; set; }
protected override void OnInitialized()
{
static string Formatter(ChartPoint point)
{
var pv = point.Coordinate.PrimaryValue;
var sv = point.StackedValue!;
return $"{pv}/{sv.Total}{Environment.NewLine}{sv.Share:P2}";
}
Series = new ISeries[]
{
new PieSeries<double>
{
Name = "Mary",
Values = new double[] { 10 },
OuterRadiusOffset = 0,
ShowDataLabels = true,
ToolTipLabelFormatter = Formatter,
DataLabelsFormatter = Formatter
},
new PieSeries<double>
{
Name = "John",
Values = new double[] { 20 },
OuterRadiusOffset = 50,
ShowDataLabels = true,
ToolTipLabelFormatter = Formatter,
DataLabelsFormatter = Formatter
},
new PieSeries<double>
{
Name = "Alice",
Values = new double[] { 30 },
OuterRadiusOffset = 100,
ShowDataLabels = true,
ToolTipLabelFormatter = Formatter,
DataLabelsFormatter = Formatter
},
new PieSeries<double>
{
Name = "Bob",
Values = new double[] { 40 },
OuterRadiusOffset = 150,
ShowDataLabels = true,
ToolTipLabelFormatter = Formatter,
DataLabelsFormatter = Formatter
}
};
}
}
DataLabelsRotation rotates the labels, in degrees. Two constants rotate each label to follow its slice.
LiveCharts.CotangentAngle aligns the text with the radius of the slice:

And LiveCharts.TangentAngle draws it across the radius:

The constants can be combined with an angle in degrees:
Series = new ISeries[]
{
new PieSeries<double>
{
Values = new double[] { 8 },
DataLabelsRotation = 30 // in degrees
},
new PieSeries<double>
{
Values = new double[] { 6 },
DataLabelsRotation = LiveCharts.TangentAngle + 30 // the tangent + 30 degrees
},
new PieSeries<double>
{
Values = new double[] { 4 },
DataLabelsRotation = LiveCharts.CotangentAngle + 30 // the cotangent + 30 degrees
}
};
Outer labels
With DataLabelsPosition set to Outer, the label is drawn outside the slice, at the middle of its angle. The chart
makes the pie smaller to leave room for the largest outer label. This sample also sets IsClockwise to false and
InitialRotation to -90, so the slices start at 12 o'clock and go counterclockwise.

@page "/Pies/OutLabels"
@using LiveChartsCore
@using LiveChartsCore.Kernel
@using LiveChartsCore.Measure
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Blazor
<PieChart
Series="Series"
IsClockwise="false"
InitialRotation="-90">
</PieChart>
@code {
private ISeries[] Series { get; set; }
protected override void OnInitialized()
{
static string LabelFormatter(ChartPoint point) =>
$"This slide takes {point.Coordinate.PrimaryValue} " +
$"out of {point.StackedValue!.Total} parts";
static string TooltipFormatter(ChartPoint point) =>
$"{point.StackedValue!.Share:P2}";
Series = new ISeries[]
{
new PieSeries<double>
{
Name = "Maria",
Values = new double[] { 8 },
ShowDataLabels = true,
DataLabelsPosition = PolarLabelsPosition.Outer,
DataLabelsSize = 15,
DataLabelsFormatter = LabelFormatter,
ToolTipLabelFormatter = TooltipFormatter
},
new PieSeries<double>
{
Name = "Susan",
Values = new double[] { 6 },
ShowDataLabels = true,
DataLabelsPosition = PolarLabelsPosition.Outer,
DataLabelsSize = 15,
DataLabelsFormatter = LabelFormatter,
ToolTipLabelFormatter = TooltipFormatter
},
new PieSeries<double>
{
Name = "Charles",
Values = new double[] { 5 },
ShowDataLabels = true,
DataLabelsPosition = PolarLabelsPosition.Outer,
DataLabelsSize = 15,
DataLabelsFormatter = LabelFormatter,
ToolTipLabelFormatter = TooltipFormatter
},
new PieSeries<double>
{
Name = "Fiona",
Values = new double[] { 3 },
ShowDataLabels = true,
DataLabelsPosition = PolarLabelsPosition.Outer,
DataLabelsSize = 15,
DataLabelsFormatter = LabelFormatter,
ToolTipLabelFormatter = TooltipFormatter
},
new PieSeries<double>
{
Name = "George",
Values = new double[] { 3 },
ShowDataLabels = true,
DataLabelsPosition = PolarLabelsPosition.Outer,
DataLabelsSize = 15,
DataLabelsFormatter = LabelFormatter,
ToolTipLabelFormatter = TooltipFormatter
}
};
}
}
Custom labels
The third generic argument of PieSeries<TModel, TVisual, TLabel> sets the class of the data labels. This sample
draws an SVG icon and the name of the series instead of a text: SvgLabel inherits from LabelGeometry and
overrides Draw, and the series sets the icon of every label in the PointMeasured event, which runs every time a
point gets its size and position.

@page "/Pies/Icons"
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Drawing
@using LiveChartsCore.SkiaSharpView.Drawing.Geometries
@using SkiaSharp
@using ViewModelsSamples.Pies.Icons
<PieChart
Series="Series">
</PieChart>
@code {
private ISeries[] Series { get; set; }
protected override void OnInitialized()
{
Series = new ISeries[]
{
new CustomPieSeries {
Name = "Chrome",
Values = new double[] { 65.72 },
IconName = "Chrome",
Icon = BrowserIcons.Chrome,
ShowDataLabels = true
},
new CustomPieSeries {
Name = "Safari",
Values = new double[] { 18.22 },
IconName = "Safari",
Icon = BrowserIcons.Safari,
ShowDataLabels = true
},
new CustomPieSeries {
Name = "Edge",
Values = new double[] { 5.31 },
IconName = "Edge",
Icon = BrowserIcons.Edge,
ShowDataLabels = true
}
};
}
public class CustomPieSeries : PieSeries<double, DoughnutGeometry, SvgLabel>
{
public CustomPieSeries()
{
PointMeasured +=
point =>
{
var label = point.Label!;
label.SvgString = Icon;
label.Name = IconName;
label.Size = 50;
label.TranslateTransform = new(-25, -25);
};
}
public string Icon { get; set; } = "";
public string IconName { get; set; } = "";
}
public class SvgLabel : LabelGeometry
{
private string? _svgString;
private SKPath _path = new();
public string? Name { get; set; }
public float Size { get; set; }
public string? SvgString
{
get => _svgString;
set
{
if (_svgString == value) return;
_svgString = value;
_path = SKPath.ParseSvgPathData(value);
}
}
public override void Draw(SkiaSharpDrawingContext context)
{
using var iconPaint = new SKPaint
{
Color = SKColors.WhiteSmoke,
Style = SKPaintStyle.Fill,
IsAntialias = true
};
Svg.Draw(context, iconPaint, _path, X, Y, Size, Size);
using var textPaint = new SKPaint
{
Color = SKColors.WhiteSmoke,
Style = SKPaintStyle.Fill,
TextSize = 16,
FakeBoldText = true,
IsAntialias = true
};
context.Canvas.DrawText(Name, X, Y - 10, textPaint);
}
}
public static class BrowserIcons
{
// from https://www.svgrepo.com/svg/500807/chrome
public static string Chrome { get; } =
"M21.25 11.031h-10.063c-0.969 0-1.844 0.313-2.625 0.781-1.344 0.844-2.25 2.344-2.313 " +
"4.031l-3.875-6.719c2.063-2.625 5.219-4.344 8.813-4.344 4.406 0 8.25 2.563 10.063 " +
"6.25zM1.875 9.75l5 8.688c0.031 0.031 0.031 0.063 0.063 0.094 0.438 0.781 1.125 " +
"1.406 1.938 1.844 0.719 0.344 1.469 0.594 2.313 0.594s1.625-0.25 2.344-0.594l-3.906 " +
"6.719c-5.438-0.781-9.625-5.438-9.625-11.094 0-2.313 0.688-4.469 1.875-6.25zM13.813 " +
"11.813h7.781c0.5 1.281 0.813 2.719 0.813 4.188 0 6.188-5.031 11.188-11.219 11.188-0.25 " +
"0-0.469 0-0.719-0.031l5-8.625c0.031-0.031 0.031-0.063 0.063-0.094 0.406-0.75 0.625-1.563 " +
"0.625-2.438v-0.156c-0.063-1.688-1-3.188-2.344-4.031zM7.469 16c0-2.094 1.625-3.75 3.719-3.75s3.75 " +
"1.656 3.75 3.75-1.656 3.75-3.75 3.75-3.719-1.656-3.719-3.75z";
// from: https://www.svgrepo.com/svg/316925/safari
public static string Safari { get; } =
"M12 3.5C7.30558 3.5 3.5 7.30558 3.5 12C3.5 13.5799 3.93054 15.0576 4.68039 16.324C4.82109 16.5617 " +
"4.74251 16.8683 4.5049 17.009C4.26729 17.1497 3.96061 17.0712 3.81992 16.8335C2.98125 15.4171 2.5 " +
"13.764 2.5 12C2.5 6.75329 6.75329 2.5 12 2.5C17.2467 2.5 21.5 6.75329 21.5 12C21.5 17.2467 17.2467 " +
"21.5 12 21.5C9.41171 21.5 7.06433 20.4642 5.3514 18.7857C5.24102 18.6776 5.18686 18.5244 5.20469 " +
"18.3709C5.22251 18.2174 5.31033 18.0808 5.44256 18.0008L13.111 13.3621L16.0946 8.3816L10.9439 " +
"11.1098L7.81033 15.6802C7.65418 15.908 7.34296 15.966 7.11521 15.8098C6.88746 15.6537 6.82941 15.3425 " +
"6.98557 15.1147L10.1887 10.4428C10.2344 10.3762 10.2956 10.3216 10.367 10.2837L17.2108 6.65874C17.4091 " +
"6.5537 17.6531 6.59365 17.8076 6.75646C17.962 6.91926 17.9891 7.16502 17.8737 7.35754L13.905 " +
"13.9825C13.8631 14.0525 13.8047 14.1112 13.7349 14.1534L6.5337 18.5095C8.01177 19.7521 9.91814 " +
"20.5 12 20.5C16.6944 20.5 20.5 16.6944 20.5 12C20.5 7.30558 16.6944 3.5 12 3.5Z";
// from: https://www.svgrepo.com/svg/452194/edge
public static string Edge { get; } =
"M10.1836 13.436H20.098C20.098 9.91613 18.5621 7.51636 14.3743 7.51636C9.42537 7.51634 4.3926 10.7381 " +
"2 14.7553C2.74111 7.78266 7.74053 2.15332 15.2673 2.15332C21.7186 2.15332 27.8309 7.08585 27.8309 " +
"15.2853V18.4026H10.2364C10.2364 22.6456 13.9377 24.3267 17.8142 24.3267C22.5317 24.3267 25.4532 22.2068 " +
"25.4532 22.2068V28.15C25.4532 28.15 22.1552 30.1533 16.8985 30.1533C10.0672 30.1533 5.24517 25.2576 " +
"5.24517 19.1697C5.24517 14.3911 8.13564 10.5759 12.1393 9.00165C10.1904 11.142 10.1835 13.436 10.1835 " +
"13.436H10.1836Z";
}
}
Nightingale rose
OuterRadiusOffset makes the slices of a series shorter: it is subtracted, in pixels, from the space the pie can
take. Giving each series a different offset draws a nightingale rose, where both the angle and the length of the
slices change. This sample also sets an InnerRadius.

@page "/Pies/NightingaleRose"
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Blazor
<PieChart
Series="Series">
</PieChart>
@code {
private ISeries[] Series { get; set; }
protected override void OnInitialized()
{
Series = new ISeries[]
{
new PieSeries<double> { Name = "Mary", Values = new double[] { 10 }, OuterRadiusOffset = 0, InnerRadius = 50 },
new PieSeries<double> { Name = "John", Values = new double[] { 20 }, OuterRadiusOffset = 50, InnerRadius = 50 },
new PieSeries<double> { Name = "Alice", Values = new double[] { 30 }, OuterRadiusOffset = 100, InnerRadius = 50 },
new PieSeries<double> { Name = "Bob", Values = new double[] { 40 }, OuterRadiusOffset = 150, InnerRadius = 50 }
};
}
}

var pieSeries = new PieSeries<int>
{
Values = new[] { 4 },
OuterRadiusOffset = 20 // mark
};
Nested pies
When the series have more than one value, every value draws a ring: the first value of every series shares the
inner ring, the second value the next ring, and so on. The rings have the same width, and each ring is a pie of its
own: the angle of a slice is its value divided by the sum of the values of that ring. A null value draws no slice
but keeps its ring, so give every series the same number of values.
This sample draws countries on the outer ring, their zones in the middle and the sales people inside. Each series
has a value in only one ring, the others are null. The series set HoverPushout to 0 so the rings stay aligned,
show data labels only on the countries, and hide the other series from the legend with IsVisibleAtLegend.

@page "/Pies/Nested"
@using LiveChartsCore
@using LiveChartsCore.SkiaSharpView.Blazor
@using LiveChartsCore.SkiaSharpView
@using LiveChartsCore.SkiaSharpView.Painting
@using LiveChartsCore.Kernel
@using SkiaSharp
<PieChart
Series="Series"
InitialRotation="120"
LegendPosition="LiveChartsCore.Measure.LegendPosition.Right">
</PieChart>
@code {
private ISeries[] Series { get; set; } = [];
protected override void OnInitialized()
{
SalesRecord[] data = [
new("Brazil", "North", "John", 10),
new("Brazil", "North", "Mary", 5),
new("Brazil", "South", "John", 20),
new("Brazil", "South", "Mary", 8),
new("Colombia", "East", "Carla", 15),
new("Colombia", "East", "Charles", 15),
new("Colombia", "West", "Carla", 25),
new("Colombia", "West", "Charles", 25),
new("Mexico", "Central", "Sophia", 30),
new("Mexico", "Central", "Petter", 5),
new("Mexico", "North", "Sophia", 30),
new("Mexico", "North", "Petter", 5)
];
double Sum(string country, string? zone = null, string? name = null) => data
.Where(x =>
(country is null || x.Country == country) &&
(zone is null || x.Zone == zone) &&
(name is null || x.Name == name))
.Sum(x => x.Value);
PieData[] pieData = [
new("Brazil", [null, null, Sum("Brazil")], "#1976d2"),
new("North", [null, Sum("Brazil", "North"), null], "#1e88e5"),
new("John", [Sum("Brazil", "North", "John"), null, null], "#2196f3"),
new("Mary", [Sum("Brazil", "North", "Mary"), null, null], "#42a5f5"),
new("South", [null, Sum("Brazil", "South"), null], "#64b5f6"),
new("John", [Sum("Brazil", "South", "John"), null, null], "#90caf9"),
new("Mary", [Sum("Brazil", "South", "Mary"), null, null], "#bbdefb"),
new("Colombia", [null, null, Sum("Colombia")], "#d32f2f"),
new("East", [null, Sum("Colombia", "East"), null], "#e53935"),
new("Carla", [Sum("Colombia", "East", "Carla"), null, null], "#f44336"),
new("Charles", [Sum("Colombia", "East", "Charles"),null, null], "#ef5350"),
new("West", [null, Sum("Colombia", "West"), null], "#e57373"),
new("Carla", [Sum("Colombia", "West", "Carla"), null, null], "#ef9a9a"),
new("Charles", [Sum("Colombia", "West", "Charles"),null, null], "#ffcdd2"),
new("Mexico", [null, null, Sum("Mexico")], "#ffa000"),
new("Central", [null, Sum("Mexico", "Central"), null], "#ffb300"),
new("Sophia", [Sum("Mexico", "Central", "Sophia"),null, null], "#ffc107"),
new("Petter", [Sum("Mexico", "Central", "Petter"),null, null], "#ffca28"),
new("North", [null, Sum("Mexico", "North"), null], "#ffd54f"),
new("Sophia", [Sum("Mexico", "North", "Sophia"), null, null], "#ffe082"),
new("Petter", [Sum("Mexico", "North", "Petter"), null, null], "#ffecb3")
];
Series = pieData.Select(x => new PieSeries<double?>
{
Name = x.Name,
Values = x.Values,
Stroke = new SolidColorPaint(SKColor.Parse("#fff"), 2),
Fill = new SolidColorPaint(SKColor.Parse(x.Color)),
HoverPushout = 0,
DataLabelsFormatter = x.Formatter,
DataLabelsSize = 20,
ShowDataLabels = x.IsTotal,
DataLabelsPosition = LiveChartsCore.Measure.PolarLabelsPosition.Outer,
IsVisibleAtLegend = x.IsTotal
}).ToArray();
}
public class SalesRecord(string country, string zone, string name, double value)
{
public string Country { get; set; } = country;
public string Zone { get; set; } = zone;
public string Name { get; set; } = name;
public double Value { get; set; } = value;
}
public class PieData(string name, double?[] values, string color)
{
public string Name { get; set; } = name;
public double?[] Values { get; set; } = values;
public string Color { get; set; } = color;
public bool IsTotal => Name is "Brazil" or "Colombia" or "Mexico";
public Func<ChartPoint, string> Formatter { get; } = point =>
$"{name}{Environment.NewLine}{point.StackedValue!.Share:P2}";
}
}
RelativeInnerRadius adds space at the inner side of every ring and RelativeOuterRadius removes space from its
outer side, both in pixels; use them to leave a gap between the rings. When a slice is capped by
MaxRadialColumnWidth, RadialAlign sets these values instead.
Tooltips and legends
The tooltip shows the hovered slice with the series Name and the value.
ToolTipLabelFormatter builds the value text; a pie tooltip has no header. The tooltip is placed next to the outer
edge of the slice, above it, or below it when there is no room. TooltipPosition is ignored, except Hidden, which
disables the tooltips.
The legend is hidden by default: set LegendPosition to Top, Bottom, Left or Right to show it. It lists one
entry per series.
The tooltips and crosshairs and legends articles cover their text, paints and custom controls.
Title and animations
The PieChart also takes the Title, DrawMargin, AnimationsSpeed and EasingFunction properties of every
chart; the basic sample sets a Title. See the
Cartesian chart control
and animations articles.
Data, names and updates
Valuestakes anyIEnumerable<T>. Use anObservableCollection<T>and the chart animates every added, removed or replaced value, see automatic updates.- To plot your own types, see mappers.
Nameis shown in tooltips and legends. When it is not set, the tooltip shows the value without a series name.IsVisibleshows or hides the series, and the other slices take its space.ZIndexsets which series draws on top.